#include "../process.h"
#include "../util.h"

#define BATCH 200000

int main(int argc, const char* argv[])

{
		fstream log(argv[1], fstream::in);
		fstream out(argv[2], fstream::out);
		int count = 0;
		cout << "start\n";
		while(!log.eof())
		{
				count ++;
				if(count%BATCH == 0)cout << ".";
				string line;
				getline(log, line);
				int del1 = line.find('\t'), del2 = line.find('\t', del1 + 1);
				string uid = line.substr(0, del1);
			 	string query = line.substr(del1 + 1, del2 - del1 - 1);
				string elem = line.substr(del2 + 1, line.length() - del2 - 1);
				query = util::normalize(query);
				if(query.length() == 0)continue;
				out << uid << "\t" << query << "\t" << elem << endl;
		}
		cout << endl <<count << "\tlines processed!\n";
		log.close();
		out.close();
		return 0;
}

//int main(int argc, const char* argv[])
//
//{
//		fstream f1(argv[1], fstream::in);
//		fstream f2(argv[2], fstream::in);
//		fstream f3(argv[3], fstream::out);
//		int count = 0;
//		while(!f1.eof())
//		{
//			string line;
//			getline(f1, line);
//			if(count ++ == 0) continue;
//			f3 << line << endl;
//		}
//		count = 0;
//		while(!f2.eof())
//		{
//			string line;
//			getline(f2, line);
//			if(count ++ == 0) continue;
//			f3 << line << endl;
//		}
//		f1.close();
//		f2.close();
//		f3.close();
//		return 0;
//}
